function listQuizPageSetup() {
	
	var quizList = document.getElementById("QuizList");
		
	if(quizList) {
		getDataReturnXML('FrontController?command=ListQuizzes', updateList, null);
	}
	
	var createQuizButton = document.getElementById("createQuizButton");
	if(createQuizButton) {
		
		createQuizButton.onclick=onClickCreateQuiz;
		if (createQuizButton.captureEvents) 
			createQuizButton.captureEvents(Event.CLICK);
	}	
}
/* for this to work you need to include global.js BEFORE this file */
registerStartupFunction( listQuizPageSetup );

function updateList(xmlDoc, obj) {
	var quizList = document.getElementById("QuizList");
	
	var quizzes = xmlDoc.getElementsByTagName("quiz");
	for(var i=0; i<quizzes.length; i++) {
		var quizName = quizzes[i].getAttribute("name");
		var quizId = quizzes[i].getAttribute("id");
		
		var textNode = document.createTextNode(quizName);
		var optionNode = document.createElement("OPTION");
		optionNode.setAttribute("value", quizId);
		optionNode.appendChild(textNode);
		
		quizList.appendChild(optionNode);
	}
	
	enableFormElements("SELECT");
	enableFormElements("INPUT");
}

function enableFormElements(tagName) {
	var inputs = document.getElementsByTagName(tagName);
	
	for(var i=0; i<inputs.length; i++) {
		inputs[i].removeAttribute("disabled");
	}
}

function onClickCreateQuiz(evt) {
	var quizNameInput = document.getElementById("NewQuizName");
	var newQuizName = new String( quizNameInput.value );
	
	if(newQuizName.trim() == "") {
		alert("Please enter a Name for the new Quiz.");
		return false;
	}
}